import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_demo/core/common/values/server.dart';
import 'package:flutter_demo/core/route/router.dart';
import 'package:flutter_demo/core/service/auth_service.dart';
import 'package:flutter_demo/ui/shared/app_theme.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';

import 'ui/pages/event/event_service.dart';

Size defaultSize = const Size(360, 690);
Future<void> main() async {
  if (Platform.isAndroid) {
    // 设置android状态栏为透明的沉浸，在渲染之前MaterialApp组件会覆盖掉这个值。
    SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarIconBrightness: Brightness.dark //状态栏的颜色根据需要更改
        );
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }

  //初始化页面缓存插件
  await GetStorage.init();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    //此种方式只能每一次使用都要调用 init
    // ScreenUtil.init(context,
    //     designSize: const Size(375, 667), //设计稿大小
    //     splitScreenMode: true,
    //     minTextAdapt: true);

    //全局配置RefreshConfiguration,配置子树下的所有SmartRefresher表现,一般存放于MaterialApp的根部
    return RefreshConfiguration(
        headerBuilder: () => const MaterialClassicHeader(
              color: Color.fromARGB(255, 201, 61, 45),
              backgroundColor: Colors.white,
            ),
        footerBuilder: () => const ClassicFooter(
              noDataText: "我是有底线的",
              canLoadingText: "松手加载更多",
            ),
        child: ScreenUtilInit(
          //屏幕适配
          designSize: const Size(375, 667),
          minTextAdapt: true,
          splitScreenMode: true,
          builder: (context, child) {
            return GetMaterialApp(
              ///去掉右上角的debug
              debugShowCheckedModeBanner: false,
              //初始化服务
              initialBinding: BindingsBuilder(() {
                Get.put(AuthService());
                Get.put(EventService());
              }),

              ///APP名称
              title: 'flutter_demo',

              ///主题
              theme: HYAppTheme.norTheme,

              ///起始路由
              initialRoute: AsRouter.initialRoute,

              ///路由和绑定
              getPages: AsRouter.getPages,
            );
          },
        ));
  }
}

@pragma('vm:entry-point')
void playerBackgroundService() {
  logger.d('start playerBackgroundService');
  print("---------playerBackgroundService------------------");
}
